package com.miyake.dsp.osa.lab.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import com.miyake.dsp.ComplexArray;

public class CsvWriter {

	public CsvWriter(ComplexArray data, String filename) {
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filename)));
			double[] real = data.getRealPart();
			double[] imag = data.getImagPart();
			for (int i = 0; i < real.length; i++) {
				writer.write(String.valueOf(real[i]));
				if (imag != null) {
					writer.write(",");
					writer.write(String.valueOf(imag[i]));
				}
				writer.newLine();
				
			}
			writer.flush();
			writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
